package org.tong.database;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.tong.bean.Student;
import org.tong.bean.Teacher;
import org.tong.database.jdbc.StudentTemplateDao;
import org.tong.database.jdbc.TeacherTemplateDao;
import org.tong.database.jpa.JpaStudentDao;
import org.tong.database.jpa.JpaTeacherDao;
import org.tong.database.mybatis.StudentMapper;
import org.tong.database.mybatis.TeacherMapper;

//@Service
public class TransactionService {

    @Autowired
    private StudentTemplateDao studentTemplateDao;

    @Autowired
    private TeacherTemplateDao teacherTemplateDao;

    @Transactional
    public int insertStudentAndTeacher(Student student, Teacher teacher) {
        return studentTemplateDao.insert(student) + teacherTemplateDao.insert(teacher);
    }

    @Autowired
    private JpaStudentDao jpaStudentDao;

    @Autowired
    private JpaTeacherDao jpaTeacherDao;

    @Transactional
    public void insertByJpa(Student student, Teacher teacher) {
        jpaStudentDao.save(student);
        jpaTeacherDao.save(teacher);
    }

    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private TeacherMapper teacherMapper;

    @Transactional
    public void insertByMybatis(Student student, Teacher teacher) {
        studentMapper.insert(student);
        teacherMapper.insert(teacher);
    }
}



